{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Selection Histogram\n",
    "===================\n",
    "This chart shows an example of using an interval selection to filter the\n",
    "contents of an attached histogram, allowing the user to see the proportion\n",
    "of items in each category within the selection.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# category: interactive\n",
    "\n",
    "import altair as alt\n",
    "alt.data_transformers.enable('json')\n",
    "from vega_datasets import data\n",
    "\n",
    "cars = data.cars.url\n",
    "\n",
    "brush = alt.selection(type='interval')\n",
    "\n",
    "points = alt.Chart().mark_point().encode(\n",
    "    x='Horsepower:Q',\n",
    "    y='Miles_per_Gallon:Q',\n",
    "    color=alt.condition(brush, 'Origin:N', alt.value('lightgray'))\n",
    ").properties(\n",
    "    selection=brush\n",
    ")\n",
    "\n",
    "bars = alt.Chart().mark_bar().encode(\n",
    "    y='Origin:N',\n",
    "    color='Origin:N',\n",
    "    x='count(Origin):Q'\n",
    ").transform_filter(\n",
    "    brush.ref()\n",
    ")\n",
    "\n",
    "alt.vconcat(points, bars, data=cars)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "env": {},
   "interrupt_mode": "signal",
   "language": "python",
   "metadata": {},
   "name": "python3"
  },
  "language": "python"
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
